package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Autowired
    private IServeService iServeService ;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO dto){
        return iServeService.page(dto);
    }


    @PostMapping("/batch")
    @ApiOperation("批量添加区域服务")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        iServeService.batchAdd(serveUpsertReqDTOList);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改服务价格")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)})
    public void update( @PathVariable("id") Long id ,@RequestParam("price") BigDecimal price){
        iServeService.update(id,price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("服务上架")
    @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    public void onSale(@PathVariable("id") Long id){
        iServeService.onSale(id);

    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除区域服务开发")
    @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    public void delete(@PathVariable("id") Long id  ){
        iServeService.deleteById(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("服务下架")
    @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    public void offSale(@PathVariable("id") Long id){
        iServeService.offSale(id);

    }
    @PutMapping("/onHot/{id}")
    @ApiOperation("开启热门")
    @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    public void  onHot( @PathVariable("id") Long id){
        iServeService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("取消热门")
    @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    public void  offHot( @PathVariable("id") Long id){
        iServeService.offHot(id);
    }

}
